package com.trace.app.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trace.app.entity.ProductImg;
import com.trace.app.entity.ResponseResult;
import com.trace.app.entity.consts.AppHttpCodeEnum;
import com.trace.app.entity.vo.PageVo;
import com.trace.app.mapper.ProductImgMapper;
import com.trace.app.service.ProductImgService;
import org.springframework.stereotype.Service;

/**
 * (ProductImg)表服务实现类
 *
 * @author lionkliu
 * @since 2024-04-28 13:35:57
 */
@Service("productImgService")
public class ProductImgServiceImpl extends ServiceImpl<ProductImgMapper, ProductImg> implements ProductImgService {

    @Override
    public ResponseResult selectPage(Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<ProductImg> queryWrapper = new LambdaQueryWrapper<>();
        Page<ProductImg> page = page(new Page<>(pageNum, pageSize), queryWrapper);
        PageVo<ProductImg> pageVo = new PageVo<>();
        pageVo.setResult(page.getRecords());
        pageVo.setTotal(page.getTotal());
        pageVo.setPageTotal(pageVo.getPageTotal(pageSize));
        return ResponseResult.okResult(pageVo);
    }

    @Override
    public ResponseResult selectOne(Integer id) {
        return ResponseResult.okResult(getById(id));
    }

    @Override
    public ResponseResult insertOne(ProductImg productImg) {
        return save(productImg) ? ResponseResult.okResult() : ResponseResult.errorResult(AppHttpCodeEnum.INSERT_ERROR);
    }

    @Override
    public ResponseResult deleteById(Integer id) {
        return removeById(id) ? ResponseResult.okResult() : ResponseResult.errorResult(AppHttpCodeEnum.DELETE_ERROR);
    }

    @Override
    public ResponseResult updateOne(ProductImg productImg) {
        LambdaUpdateWrapper<ProductImg> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.eq(ProductImg::getId, productImg.getId());
        // TODO
        update(null, updateWrapper);
        return ResponseResult.okResult();
    }
}

